
<%@include file="/html/portlet/init.jsp" %>
<portlet:actionURL name="saveAccountDetails" var="saveAccountDetails" />
<%	
	String bucketList="bucketList";
	List<PaypalBucket> paypalBuckets = PaypalBucketLocalServiceUtil.getByCompanyId(themeDisplay.getCompanyId());
	if (paypalBuckets == null || paypalBuckets.isEmpty() ) {
		List<PaypalBucket> newList = new ArrayList<PaypalBucket>();
		newList.add(new PaypalBucketImpl());
		paypalBuckets = newList;	
	}
%>
<div>
	<liferay-ui:error key="DeleteKey" message="Last entry can not Delete" />
	<liferay-ui:error key="titleKey" message="Title can not be empty" />
	<liferay-ui:error key="uNameKey" message="User Name can not be empty" />
	<liferay-ui:error key="passKey" message="Password can not be empty" />
	<liferay-ui:error key="minLengthKey" message="Password can not be less then 6 charachter" />
	<liferay-ui:error key="maxLengthKey" message="Password can not be more then 25 charachter" />
	<liferay-ui:error key="signKey" message="Signature can not be empty" />
	<liferay-ui:error key="pKey" message="primary can not be empty" />
</div>

<div class="portlet-msg-info">
	<liferay-ui:message	key="All fields except description are mandatory." />
</div>
<aui:form name="fm" action="<%= saveAccountDetails.toString() %>" method="POST"  >
	<aui:fieldset cssClass="<%= renderResponse.getNamespace() + bucketList %>" >    
		<%	
			int count = 1;
			for (PaypalBucket paypalBucket : paypalBuckets) {
		%>
					<div class="lfr-form-row lfr-form-row-inline">
						<aui:fieldset column="<%= true %>" cssClass="aui-w20">
							<aui:input type="hidden" name='<%= "bucketId" + count %>' value="<%= paypalBucket.getBucketId() %>"/>
							
							<aui:input fieldParam="Title" maxLength="15" name='<%= "title" + count %>' value="<%= paypalBucket.getTitle() %>"  label="Title" onkeypress="return checkAlpha(event,/[a-zA-Z ]/);" >
								<aui:validator name="required" />
							</aui:input>
			
							<aui:input fieldParam="APIUserName" maxLength="30" name='<%= renderResponse.getNamespace()+"apiUserName"+count %>'  value="<%= paypalBucket.getApiUserName() %>" label="API User Name"  >
								<aui:validator name="required" />
							</aui:input>
							
							<aui:input fieldParam="APIPassword" maxLength="25" type="password" name='<%= "apiPassword" + count %>' value="<%= paypalBucket.getApiPassword() %>" label="API Password">
								<aui:validator name="required" />
								<aui:validator name="rangeLength" errorMessage="should be between 6-25 character ">[6,25]</aui:validator>
							</aui:input>
						
							<aui:input checked="<%= paypalBucket.getDefaultEntry() %>"  name="defaultEntry" label="primary" type="radio" 
											value="<%= count %>" helpMessage="Select for making this account as primary for crediting payment" >
								<aui:validator name="required" errorMessage="Select at least one Primary Account "/>
							</aui:input>
						</aui:fieldset>

						<aui:fieldset column="<%= true %>" cssClass="aui-w20">			
								<aui:input type="textarea" cols="50" rows="3" fieldParam="APISignature"  name='<%= "apiSignature" + count %>'
									value="<%= paypalBucket.getApiSignature() %>" label="API Signature" >
									<aui:validator name="required" />
								</aui:input>
						
						 	  <aui:input type="textarea" cols="55" rows="10" fieldParam="description"  name='<%= "description" + count %>'  value="<%= paypalBucket.getDescription() %>" label="Description"/>
						</aui:fieldset>
					</div>	
				<%	
				count++;
			}
		%>
	</aui:fieldset>
	<aui:button type="Submit" value="Save" name="Submit" />
</aui:form>
		
<aui:script use="paypalbucket-auto-fields">
	 new Liferay.HopeAutoFields(
	    {
	        contentBox: 'fieldset.<portlet:namespace />bucketList',
	        fieldIndexes: '<portlet:namespace />bucketListIndexes'
	    }
	).render();
</aui:script>
<hr/>